# coding=utf-8

import web
import json
from basecontroller import basecontroller
from services.monkeyservices import monkeyservices


class TaskController(basecontroller):

    def POST(self, path):
        super(TaskController, self).POST(path)
        data = web.data()
        # monkeyservices.set_a_device_info(data)
        return "1"

    def GET(self, path):
        print 'task path', path
        if path == 'task_monkey_lisk':
            devices = monkeyservices().get_all_tasks_info()
            return json.dumps(devices)
        elif 'terminate' in path:
            pid = path.split('/')[1]
            return monkeyservices().terminatePid(pid)
        elif path == '':
            pass
        try:
            import os
            print os.path.abspath(".")
            return open('./pages/helios/monkey/' + path).read()
        except IOError, e:
            print e.message
